package com.light.gulimall.product.controller;

import com.light.common.utils.PageUtils;
import com.light.common.utils.R;
import com.light.gulimall.product.entity.BrandEntity;
import com.light.gulimall.product.entity.CategoryBrandRelationEntity;
import com.light.gulimall.product.service.CategoryBrandRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 品牌分类关联
 *
 * @author minmin
 * @email 980680541@gmail.com
 * @date 2024-07-16 19:47:27
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.saveCategoryBrandRelation(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/catelog/list")
    public R getCatelogList(){
        List<CategoryBrandRelationEntity> list = categoryBrandRelationService.list();
        return R.ok().put("data",list);
    }

    /**
     * 获取分类关联的品牌
     * @param catId 分类ID
     * @return  查询结果集
     */
    @GetMapping("/brands/list")
    public R getBrandsList(@RequestParam(value = "catId",required = false)Long catId){
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.getBrandsList(catId);
        return R.ok().put("data",data);
    }



}
